Component({
  /**
   * 组件的属性列表
   */
  properties: {
    value: {
      type: String,
      observer: function(newVal, oldVal, changePath) {
        this.setData({
          display: newVal
        })
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    display: '',

    mcurrentDate: new Date().getTime(),
    minDate: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      } else if (type === 'month') {
        return `${value}月`;
      } else if (type === 'day') {
        return `${value}日`
      }
      return value;
    },

  },

  /**
   * 组件的方法列表
   */
  methods: {
    showPopup() {
      this.setData({ show: true })
    },
  
    onClose() {
      this.setData({ show: false })
      this.triggerEvent('closechang', this.data.show)
    },

    bindtap() {
      this.setData({ show: true })
      this.triggerEvent('canchang', this.data.show)
    },

    confirm(event) {
      let val = new Date(event.detail)
      let year = val.getFullYear()
      let month = val.getMonth() + 1
      let day = val.getDate()
      if (month >= 1 && month <= 9) { month = `0${month}` }
      if (day >= 1 && day <= 9) { day = `0${day}` }
      let display = `${year}-${month}-${day}`
      this.setData({
        display: display
      })
      this.triggerEvent('change', display)
      this.setData({ show: false })
    },
    cancel() {
      this.setData({ show: false })
      this.triggerEvent('closechang', this.data.show)
    }

  }
})
